﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="admin_Modules_NewsEvent_Images_Default" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link href="/admin/resources/css/base.css" rel="stylesheet" type="text/css" />
    <script src="/admin/resources/js/base.js" type="text/javascript"></script>
    <script type="text/javascript">

        ///Quản lí chuyên mục ảnh
        var loadAddOrEditImageCategoryForm = function (id) {
            top.createWindow('addOrEditImageCategory', 'Modules/common/Images/AddOrEditImageCategory.aspx?id=' + id + '&cbFX=reloadImageCategory&tId=' + getTabPanelID(), 'Tạo chuyên mục', 680, 420, true)
        }

        var reloadImageCategory = function () {
            PagingToolBar1.changePage(1);

        }

        var commandHandler = function (cmd, record) {
            switch (cmd) {
                case "edit":
                    loadAddOrEditImageCategoryForm(record.data.ID);
                    break;
                case "view":
                    hdfCurrentCategoryId.setValue(record.data.ID);
                    PagingToolBar2.changePage(1);
                    break;
            }
        }

        var loadEntityByCategory = function () {
            hdfCurrentCategoryId.setValue(0);
            PagingToolBar2.changePage(1);
        }

        var rowSelectImageCategories = function (sl, index, record) {
            var selectRows = sl.grid.getRowsValues({ selectedOnly: true });
            var count = selectRows.length;
            btnDeleteImageCategories.setDisabled(count == 0);
        }

        var checkNoneAllSelectImageCategories = function (model) {
            var count = model.getSelections().length;
            btnDeleteImageCategories.setDisabled(count == 0);

        }

        var rowDeSelectImageCategories = function (sl, index, record) {
            var selectRows = sl.grid.getRowsValues({ selectedOnly: true });
            var count = selectRows.length;
            btnDeleteImageCategories.setDisabled(count == 0);
        }

        function confirmDeleteImageCategories() {
            parent.Ext.Msg.confirm('Xác nhận', '<span style="color:red;text-align:center;">Xóa chuyên mục ảnh?<br>Xóa chuyên mục ảnh sẽ xóa hết ảnh thuộc về chuyên mục.</span>', function (btn) {
                if (btn == "yes") {
                    btnDoDeleteImageCategories.fireEvent('click', null);
                }
            });
        }

        /// Quản lí ảnh
        var loadAddOrEditImage = function (id) {
            top.createWindow('addOrEditImage', 'Modules/common/Images/AddOrEditImage.aspx?id=' + id + '&cbFX=reloadImage&tId=' + getTabPanelID(), 'Thêm, sửa ảnh', 680, 420, true)
        }


        var rowSelectImage = function (sl, index, record) {
            var selectRows = sl.grid.getRowsValues({ selectedOnly: true });
            var count = selectRows.length;
            btnDeleteImage.setDisabled(count == 0);
        }

        var checkNoneAllSelectImage = function (model) {
            var count = model.getSelections().length;
            btnDeleteImage.setDisabled(count == 0);

        }

        var rowDeSelectImage = function (sl, index, record) {
            var selectRows = sl.grid.getRowsValues({ selectedOnly: true });
            var count = selectRows.length;
            btnDeleteImage.setDisabled(count == 0);
        }

        var reloadImage = function () {
            PagingToolBar2.changePage(1);
        }

        var imageCommandHandler = function (cmd, record) {

            switch (cmd) {
                case "edit":
                    loadAddOrEditImage(record.data.ID);
                    break;
            }
        }

        var confirmDeleteImage = function () {
            parent.Ext.Msg.confirm('Xác nhận', '<span style="color:red;text-align:center;">Xóa ảnh?</span>', function (btn) {
                if (btn == "yes") {
                    btnDeleteImageAction.fireEvent('click', null);
                }
            });
        }

        var renderImage = function (value) {
            return "<img src='" + value + "?w=80' />";
        }


        var loadCategoryOrderForm = function () {
            var url = "/admin/modules/common/Images/SortCategory.aspx?id=" + id + "&cbFX=reloadImageCategory&tId=" + getTabPanelID();
            window.top.createWindow('sortImagesCategory', url, 'Sắp xếp chuyên mục', 580, 460, true);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager runat="server" ID="SM">
    </ext:ResourceManager>
    <%--Store image category--%>
    <ext:Store ID="storeImageCategory" runat="server" RemoteSort="false" AutoLoad="true">
        <Reader>
            <ext:JsonReader IDProperty="ID" Root="imageCategories" TotalProperty="totalCount">
                <Fields>
                    <ext:RecordField Name="ID" />
                    <ext:RecordField Name="Name" />
                    <ext:RecordField Name="Order" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <SortInfo Field="Order" />
        <AutoLoadParams>
            <ext:Parameter Name="start" Value="0" Mode="Raw" />
            <ext:Parameter Name="limit" Value="20" Mode="Raw" />
        </AutoLoadParams>
        <Proxy>
            <ext:HttpProxy Json="true" Url="GetImageCategories.ashx" Method="GET">
            </ext:HttpProxy>
        </Proxy>
    </ext:Store>
    <%--Store File images--%>
    <ext:Store runat="server" ID="storeImages" AutoLoad="true">
        <Reader>
            <ext:JsonReader IDProperty="ID" Root="imageInCate" TotalProperty="totalCount">
                <Fields>
                    <ext:RecordField Name="Name" />
                    <ext:RecordField Name="Url" />
                    <ext:RecordField Name="ID" />
                    <ext:RecordField Name="Order" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <Proxy>
            <ext:HttpProxy Json="true" Url="GetImageInCategory.ashx" Method="GET">
            </ext:HttpProxy>
        </Proxy>
        <AutoLoadParams>
            <ext:Parameter Name="start" Value="0" Mode="Raw" />
            <ext:Parameter Name="limit" Value="10" Mode="Raw" />
        </AutoLoadParams>
        <BaseParams>
            <ext:Parameter Name="categoryId" Value="#{hdfCurrentCategoryId}.getValue()" Mode="Raw" />
        </BaseParams>
    </ext:Store>
    <%--File context menu--%>
    <ext:Menu ID="mnImageContext" runat="server">
        <Items>
            <ext:MenuItem Text="Sửa">
            </ext:MenuItem>
            <ext:MenuSeparator>
            </ext:MenuSeparator>
            <ext:MenuItem Text="Xóa">
            </ext:MenuItem>
        </Items>
    </ext:Menu>
    <ext:Hidden ID="hdfCurrentCategoryId" runat="server">
    </ext:Hidden>
    <ext:Viewport ID="ViewPort2" runat="server">
        <Items>
            <ext:BorderLayout ID="BorderLayout1" runat="server">
                <West MinWidth="300" MaxWidth="300" Collapsible="false" Split="true" MarginsSummary="5 0 5 5"
                    CMarginsSummary="5 5 5 5">
                    <ext:Panel Border="true" Collapsible="false" Title="Danh sách chuyên mục Ảnh" Width="300"
                        Layout="fit" ID="panelImageCategory" runat="server">
                        <TopBar>
                            <ext:Toolbar>
                                <Items>
                                    <ext:Button runat="server" ID="btnAddImageCategory" Text="Thêm chuyên mục" Icon="Add">
                                        <Listeners>
                                            <Click Handler=" loadAddOrEditImageCategoryForm(0);" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:ToolbarSeparator>
                                    </ext:ToolbarSeparator>
                                    <ext:Button runat="server" ID="btnCategoryOrder" Text="Sắp xếp" Icon="SortAscending">
                                        <Listeners>
                                            <Click Handler=" loadCategoryOrderForm();" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:ToolbarSeparator>
                                    </ext:ToolbarSeparator>
                                    <ext:Button Text="Xóa" Icon="Delete" ID="btnDeleteImageCategories" Disabled="true">
                                        <Listeners>
                                            <Click Handler=" confirmDeleteImageCategories();"></Click>
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button Hidden="true" ID="btnDoDeleteImageCategories" runat="server">
                                        <DirectEvents>
                                            <Click OnEvent="DeleteImageCategories" Before="parent.Ext.Msg.wait('Đang cập nhật dữ liêu...', 'Saving');    "
                                                Success="parent.Ext.Msg.hide();">
                                            </Click>
                                        </DirectEvents>
                                    </ext:Button>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                        <Items>
                            <ext:GridPanel ID="gridViewImageCategories" runat="server" StripeRows="true" Header="false"
                                Layout="Fit" Frame="false" StoreID="storeImageCategory" Border="false" TrackMouseOver="true"
                                BodyBorder="false" AutoExpandColumn="Name" Title="Toàn bộ Văn bản nội bộ">
                                <ColumnModel ID="ColumnModel1" runat="server">
                                    <Columns>
                                        <ext:RowNumbererColumn Header="#" Width="30" Align="Center">
                                        </ext:RowNumbererColumn>
                                        <ext:CommandColumn Align="Center" Width="30" Header="Sửa" ButtonAlign="Center">
                                            <Commands>
                                                <ext:GridCommand Icon="TableEdit" CommandName="edit" ToolTip-Text="<b style='color:blue;'>Sửa</b>">
                                                </ext:GridCommand>
                                            </Commands>
                                        </ext:CommandColumn>
                                        <ext:Column Header="Tiêu đề" DataIndex="Name" Sortable="true">
                                        </ext:Column>
                                        <ext:Column Header="STT" DataIndex="Order" Sortable="true" ColumnID="Order" Width="50">
                                        </ext:Column>
                                        <ext:CommandColumn Align="Center" Width="26" ButtonAlign="Center">
                                            <Commands>
                                                <ext:GridCommand Icon="Picture" CommandName="view" ToolTip-Text="<b style='color:blue;'>Xem ảnh</b>">
                                                </ext:GridCommand>
                                            </Commands>
                                        </ext:CommandColumn>
                                    </Columns>
                                </ColumnModel>
                                <SelectionModel>
                                    <ext:CheckboxSelectionModel ID="CheckboxSelectionModel1" runat="server">
                                        <Listeners>
                                            <RowSelect Fn="rowSelectImageCategories" />
                                            <RowDeselect Fn="rowDeSelectImageCategories" />
                                            <SelectionChange Fn="checkNoneAllSelectImageCategories" />
                                        </Listeners>
                                    </ext:CheckboxSelectionModel>
                                </SelectionModel>
                                <Listeners>
                                    <Command Handler="commandHandler(command,  record);" />
                                </Listeners>
                                <LoadMask ShowMask="true" Msg="Đang tải dữ liệu, vui lòng chờ ..." />
                            </ext:GridPanel>
                        </Items>
                        <BottomBar>
                            <ext:PagingToolbar ID="PagingToolBar1" runat="server" AfterPageText="" BeforePageText="Trang&nbsp;"
                                StoreID="storeImageCategory" DisplayMsg="{0}-{1}/{2}" FirstText="Đầu" LastText="Cuối"
                                EmptyMsg="" NextText="Tiếp" PageSize="20" PrevText="Trước" RefreshText="Làm mới">
                            </ext:PagingToolbar>
                        </BottomBar>
                    </ext:Panel>
                </West>
                <Center MarginsSummary="5 5 5 0" CMarginsSummary="5 5 5 0">
                    <ext:Panel runat="server" ID="ImagePanel" Cls="images-view" Frame="false" Border="true"
                        Layout="fit" AutoScroll="true" Title="Danh sách ảnh">
                        <TopBar>
                            <ext:Toolbar>
                                <Items>
                                    <ext:Button runat="server" Icon="ApplicationViewColumns" Text="Tất cả" ID="btnViewAll">
                                        <Listeners>
                                            <Click Handler="loadEntityByCategory(0);" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:ToolbarSeparator>
                                    </ext:ToolbarSeparator>
                                    <ext:Button runat="server" ID="btnAddImage" Text="Thêm ảnh" Icon="Add">
                                        <Listeners>
                                            <Click Handler="loadAddOrEditImage(0)" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:ToolbarSeparator>
                                    </ext:ToolbarSeparator>
                                    <ext:Button Text="Xóa" Icon="Delete" ID="btnDeleteImage" Disabled="true">
                                        <Listeners>
                                            <Click Handler=" confirmDeleteImage();"></Click>
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button Hidden="true" ID="btnDeleteImageAction" runat="server">
                                        <DirectEvents>
                                            <Click OnEvent="DeleteImage" Before="parent.Ext.Msg.wait('Đang cập nhật dữ liêu...', 'Saving');    "
                                                Success="parent.Ext.Msg.hide();">
                                            </Click>
                                        </DirectEvents>
                                    </ext:Button>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                        <Items>
                            <ext:GridPanel ID="GridPanel1" runat="server" StripeRows="true" Header="false" Layout="Fit"
                                Frame="false" StoreID="storeImages" Border="false" TrackMouseOver="true" BodyBorder="false"
                                AutoExpandColumn="Name" Title="Toàn bộ Văn bản nội bộ">
                                <ColumnModel ID="ColumnModel2" runat="server">
                                    <Columns>
                                        <ext:RowNumbererColumn Header="#" Width="30" Align="Center">
                                        </ext:RowNumbererColumn>
                                        <ext:CommandColumn Align="Center" Width="26">
                                            <Commands>
                                                <ext:GridCommand Icon="TableEdit" CommandName="edit" ToolTip-Text="<b style='color:blue;'>Sửa</b>">
                                                </ext:GridCommand>
                                            </Commands>
                                        </ext:CommandColumn>
                                        <ext:Column Header="Tiêu đề" DataIndex="Name" Sortable="true" ColumnID="Title">
                                        </ext:Column>
                                        <ext:Column Header="Ảnh" DataIndex="Url" Sortable="true" Width="100" Align="Center">
                                            <Renderer Fn="renderImage" />
                                        </ext:Column>
                                        <ext:Column Header="TT" DataIndex="Order" Sortable="true" ColumnID="Order" Width="36">
                                        </ext:Column>
                                    </Columns>
                                </ColumnModel>
                                <SelectionModel>
                                    <ext:CheckboxSelectionModel ID="CheckboxSelectionModel2" runat="server">
                                        <Listeners>
                                            <RowSelect Fn="rowSelectImage" />
                                            <RowDeselect Fn="rowDeSelectImage" />
                                            <SelectionChange Fn="checkNoneAllSelectImage" />
                                        </Listeners>
                                    </ext:CheckboxSelectionModel>
                                </SelectionModel>
                                <Listeners>
                                    <Command Handler="imageCommandHandler(command,  record);" />
                                </Listeners>
                                <LoadMask ShowMask="true" Msg="Đang tải dữ liệu, vui lòng chờ ..." />
                            </ext:GridPanel>
                        </Items>
                        <BottomBar>
                            <ext:PagingToolbar ID="PagingToolBar2" runat="server" PageSize="10" StoreID="storeImages"
                                AfterPageText="" BeforePageText="Trang&nbsp;" DisplayMsg="{0}-{1}/{2}" EmptyMsg=""
                                FirstText="Đầu" LastText="Cuối" NextText="Tiếp" PrevText="Trước" RefreshText="Làm mới" />
                        </BottomBar>
                    </ext:Panel>
                </Center>
            </ext:BorderLayout>
        </Items>
    </ext:Viewport>
    </form>
</body>
</html>
